/**
 * @Created Oct 25, 2011 3:35:29 PM
 * @author cry30
 */
package com.philip.journal.core;

import static org.junit.Assert.fail;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.log4j.Logger;
import org.junit.Assert;

/**
 * Composition common testing util.
 */
public class JournalTestCommon {

    /** Subclass logger. */
    private final Logger logger = Logger.getLogger(getClass()); // NOPMD by r39 on 3/30/11 6:02 PM

    /** Sequence for generating unique ID. */
    private transient int genId = 0;

    /** Test artifact. Test username. */
    public static final String TEST_USERNAME = "kratos666";
    /** Test artifact. Test non existing username. */
    public static final String TEST_X_USERNAME = "ganondorf";
    /** Test artifact. Test password. */
    public static final String TEST_PASSWORD = "password";
    /** Test artifact. Test incorrect password. Must be different from password in length as well. */
    public static final String TEST_X_PASSWORD = "xpassword";
    /** Test artifact. Test new password. */
    public static final String TEST_N_PASSWORD = "npassword";
    /** Test artifact. Test checksum. */
    public static final String TEST_CHECKSUM = "checksum";

    /** Test Journal Exception Message. */
    public static final String TEST_JRNL_ERRORMSG = "Test Journal Exception";

    /** RTFC. */
    public static final String MSG_TSTB = "Too Simple to break.";

    /** RTFC. */
    public static final String TODO_MSG = "Not yet implemented.";

    /** @param throwable Unexpected exception that was thrown. */
    public void failUnexpectedException(final Throwable throwable) {
        String message = throwable.getMessage();
        if (message == null) {
            message = throwable.getClass().getSimpleName();
        }
        Assert.fail(message + " was not expected thrown.");
    }

    /** @param throwable Expected exception that was thrown. */
    public void failExpectedException(final Class<?> throwable) {
        Assert.fail(throwable.getSimpleName() + " was expected thrown.");
    }
    /** @param message Expected exception that was thrown. */
    public void failExpectedException(final String message) {
        Assert.fail(message);
    }

    /** Convenience method. */
    public void failedOnExpectedException() {
        fail("Expected exception was not thrown.");
    }

    /** Convenience method. */
    public void failUnimplemented()
    {
        fail("Not yet implemented.");
    }

    /**
     * Helper method to return the current date.
     *
     * @return current date.
     */
    public Date getCurrentDate() {
        return new Date();
    }

    /**
     * Helper method to return tomorrows date.
     *
     * @return tomorrows date.
     */
    public Date getTomorrowDate()
    {
        final Calendar calendar = new GregorianCalendar();
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        return calendar.getTime();
    }

    /**
     * TODO: Re-factor to guarantee it is unique. Utility method to generate a unique ID based on calling class and
     * current time.
     *
     * @return unique ID.
     */
    public synchronized String generateUniqueId() {
        return Thread.currentThread().getStackTrace()[0].getClassName() + genId++;
    }

    /** @return the logger. */
    public Logger getLogger() {
        return logger;
    }

}
